﻿
//格式化是否是负责人
var fnFormatText = function (elCell, oRecord, oColumn, sData) {
    var pid = oRecord.getData(const_entityID);
    if (sData == pid) {
        elCell.innerHTML = "<font color='red'>是</font>";
    } else {
        elCell.innerHTML = "否";
    }
}
//新增职位
/* 对应的方法和ID*/

var fnAddPosition = function () {
    if (fkey != "") {
        _fn = GetSelected;
        document.getElementById("EditUIWindow1").src = "../../EditWidows/OrganizationalManager/CreatePosition.aspx?id=" + fkey + "";
        YAHOO.example.container.dialog2.show();
    }
    else {
        alert("操作无效,请先选择左侧组织架构树");
    }
}
//设置负责人
var fnSetManager = function () {
    var recordID = myDataTable.getSelectedRows()[0];
    record = myDataTable.getRecord(recordID);
    if (record == null) {
        alert("请选择一条记录");
        return;
    }
    /// <reference path="../EditWidows/OrganizationalManager/DataProcessin.aspx" />   
    var SetManagerURL = "../EditWidows/OrganizationalManager/DataProcessin.aspx";
    var vid = record.getData(const_entityID);
    var dpid = record.getData("DeptID");
    if (vid != undefined && dpid != undefined) {
        if (confirm("您确定设置该职位为部门唯一负责人吗？")) {
            var SaveUrl = SetManagerURL + "?r=" + Math.random() + "&action=update&entity=DatPositions&manager=" + vid + "&json=&deptid=" + dpid;
            YAHOO.util.Connect.asyncRequest('POST', SaveUrl, {
                success: function (res) {
                    try {
                        var str = res.responseText;
                        if (str == "1") {
                            alert("设置成功!");
                            Native("", fkey);
                            // RefreshData();
                        }
                        else {
                            alert(str + "\n" + "操作失败!");
                        }
                    }
                    catch (e) {
                    }
                    finally {
                    }
                },
                failure: function (error) {
                    alert("数据错误：" + error.statusText);
                }
            }, null);
        }
    }
}


/* -----------------------------------------
*  定义对话窗口功能
*  
*
*
*--------------------------------------------*/
YAHOO.namespace("example.container");
YAHOO.util.Event.onDOMReady(function () {
    // Define various event handlers for Dialog
    var handleSubmit = function () {
        var editwindow = document.getElementById("EditUIWindow");
        if (editwindow) {
            editwindow.contentWindow.Save();


























        }
    };

    var handleCancel = function () {
        this.cancel();
    };
    var handleSubmit1 = function () {
        var editwindow = document.getElementById("EditUIWindow1");
        if (editwindow) {
            editwindow.contentWindow.ChooseInfo();
        }
        YAHOO.example.container.dialog2.hide();
    }
    var handleSuccess = function (o) {
        var response = o.responseText;
        response = response.split("<!")[0];
        document.getElementById("resp").innerHTML = response; fnSetField();
    };
    var handleFailure = function (o) {
        alert("Submission failed: " + o.status);
    };

    // Remove progressively enhanced content class, just before creating the module
    YAHOO.util.Dom.removeClass("dialog1", "yui-pe-content");

    /*
    数据编辑
    */
    YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
							    { width: const_EditWindowWidth,
							        height: const_EditWindowHeight,
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "保存11", handler: handleSubmit, isDefault: true },
								          { text: "取消", handler: handleCancel}]
							    });
    /*
    
    */
    YAHOO.example.container.dialog2 = new YAHOO.widget.Dialog("dialog2",
							    { width: "420px",
							        height: "400px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "保存", handler: handleSubmit1, isDefault: true },
								          { text: "取消", handler: handleCancel}]
							    });

    /*
    
    */
    YAHOO.example.container.dialog3 = new YAHOO.widget.Dialog("dialog3",
							    { width: "350px",
							        height: "90px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [{ text: "确定", handler: DeleteData, isDefault: true },
								          { text: "取消", handler: handleCancel}]
							    });

    /*
    查询
    */
    YAHOO.example.container.dialog4 = new YAHOO.widget.Dialog("dialog4",
							    { width: "650px",
							        height: "350px",
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [
							    { text: "取消", handler: handleCancel}]
							    });
    YAHOO.example.container.dialog5 = new YAHOO.widget.Dialog("dialog5",
							    { width: const_EditWindowWidth,
							        height: const_EditWindowHeight,
							        fixedcenter: true,
							        visible: false,
							        draggable: true,
							        close: true,
							        autofillheight: "body",
							        constraintoviewport: true,
							        buttons: [
							    { text: "取消", handler: handleCancel}]
							    });
    // Validate the entries in the form to require that both first and last name are entered


    // Wire up the success and failure handlers
    YAHOO.example.container.dialog1.callback = { success: handleSuccess,
        failure: handleFailure
    };

    // Render the Dialog
    YAHOO.example.container.dialog1.render();
    YAHOO.example.container.dialog2.render();
    YAHOO.example.container.dialog3.render();
    YAHOO.example.container.dialog4.render();
    YAHOO.example.container.dialog5.render();

    /* 对话框
    ****/
    //----------------------------------------------------*/
    // YAHOO.util.Event.addListener("btnAddNew", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);



    //拖动大小
    var resize = new YAHOO.util.Resize("dialog1", {
        handles: ["br"],
        autoRatio: false,
        minWidth: 450,
        minHeight: 400,
        status: false
    });
    resize.on("startResize", function (args) {

        if (this.cfg.getProperty("constraintoviewport")) {
            var D = YAHOO.util.Dom;

            var clientRegion = D.getClientRegion();
            var elRegion = D.getRegion(this.element);

            resize.set("maxWidth", clientRegion.right - elRegion.left - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
            resize.set("maxHeight", clientRegion.bottom - elRegion.top - YAHOO.widget.Overlay.VIEWPORT_OFFSET);
        } else {
            resize.set("maxWidth", null);
            resize.set("maxHeight", null);
        }

    }, YAHOO.example.container.dialog1, true);
    resize.on("resize", function (args) {
        var panelHeight = args.height;
        this.cfg.setProperty("height", panelHeight + "px");
    }, YAHOO.example.container.dialog1, true);
});

